<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>子传父</title>
</head>
<body>
    <div id="app">
        <mark>{{i}}</mark>
        <!-- ④ -->
        <child @son="getData"></child>
    </div>
    <script src="../vue.js"></script>
    <script>
        let vm = new Vue({
            el: '#app',
            data:{
                i: ''
            },
            methods: {
                //监听自定义事件，并接收数据⑤
                getData(i){
                    this.i = i;
                }
            },
            components:{
                child: {
                    //①
                    template:`<div>
                        <hr>
                        <p>儿子</p>
                        <button @click="son">到爸爸</button>
                        <hr>
                        </div>`,
                    data(){
                        //②
                        return{
                            msg:'爸爸 我是您的儿子'
                        }
                    },
                    methods: {
                        //③
                        son() {
                            //子传父代码
                            //发射 (自定义事件，带上数据作为参数)
                            this.$emit('son',this.msg);
                        }
                    }
                }
            }
        })
    </script>
</body>
</html>